#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int NB = 4 * 1E6 + 10;
const int OFFSET = 1e6 + 1;
int n, m;
int arr[N];
int help[NB];   // 用来处理记录从头开始矿的数量
int count1[NB]; // 用来记录每个点的数量
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
        int tem = arr[i];
        count1[tem + OFFSET]++;
    }
    for (int i = 1; i < NB; i++)
    {
        help[i] = help[i - 1] + count1[i];
    }
    int ret = 0;
    // 向右走k步
    for (int i = 0; i <= m; i++)
    {
        int l = 2 * i - m + OFFSET;
        int r = i + OFFSET;
        // 约束索引范围并检查有效性
        // l = max(1, l);
        // r = min(r, NB - 1);
        // if (l > r)
        //     continue;
         ret = max(ret, help[r] - help[l - 1]);
        //ret = max(ret, help[r] - (l > 0 ? help[l - 1] : 0));
    }
    for (int i = 0; i <= m; i++)
    {
        int l = -i + OFFSET;
        int r = m - 2 * i + OFFSET;
        // 约束索引范围并检查有效性
        // l = max(1, l);
        // r = min(r, NB - 1);
        //   if (l > r)
        //     continue;
         ret = max(ret, help[r] - help[l-1]);
        //ret = max(ret, help[r] - (l > 0 ? help[l - 1] : 0));
    }
    cout << ret << endl;
    return 0;
}